import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn,BeforeInsert, OneToOne, JoinColumn} from 'typeorm';
import { UserDetails } from './user.detail.entity';
export enum UserRole {
  SuperAdmin = 'superadmin',
  Admin = 'admin',
  User = 'user',
}
export const RoleHierarchy = {
  [UserRole.SuperAdmin]: 3,
  [UserRole.Admin]: 2,
  [UserRole.User]: 1,
};

@Entity()
export class NV_Users {
  // 自增列
  @PrimaryGeneratedColumn()
  id: number;
  // 用户ID
  @Column({ type: 'varchar', length: 20, unique: true })
  user_id: string;

  @CreateDateColumn({ type: 'timestamp' })
  create_time: Date;

  @UpdateDateColumn({ type: 'timestamp' })
  Update_time: Date;

  @Column({ type: 'varchar', length: 255 })
  username:string

  @Column({ type: 'varchar', length: 255 })
  password: string;

  @Column({ type: 'varchar', length: 50 }) // 角色字段
  role: string;

  // 一对一关联 UserDetails 实体
  @OneToOne(() => UserDetails, (details) => details.user, { cascade: true })
  @JoinColumn()
  details: UserDetails;
}